﻿layui.use(['form', 'layedit', 'laydate'], function () {
    var form = layui.form
        , layer = layui.layer
        , layedit = layui.layedit
        , laydate = layui.laydate;
    var jsondata;
    var formId;
    form.on('select(flowSelect)', function (data) {
        $("#FlowId").val($("#FlowsId").val())
        $.ajax({
            url: '/Flow/GetFlowId',
            type: 'post',
            dataType: 'json',
            async: false,
            data: {
                id: $("#FlowsId").val()
            },
            success: function (d) {
                jsondata = d.data[0].content;
                formId = d.data[0].formId;
                $("#FlowContent").val(d.data[0].content);
            }
        });
        LoadFlow();
        LoadForm(formId)
    });
    function LoadForm(id)
    {
        $.getJSON("/Form/GetFormId?id=" + id, function (data) {
            $("#content").html(data.data[0]["Content"]);
            $("#FormContent").val(data.data[0]["ContentParse"])
            $("#Fields").val(data.data[0]["Fields"]);
        });
    }
    function LoadFlow() {
        $("#demo").empty();
        var property = {
            width: 1072,
            height: 600,
            toolBtns: ["start round", "end round", "task round", "node", "chat", "state", "plug", "join", "fork", "complex mix"],
            haveHead: false,
            headBtns: ["new", "open", "save", "undo", "redo", "reload"],//如果haveHead=true，则定义HEAD区的按钮
            haveTool: false,
            haveGroup: true,
            useOperStack: true
        };
        var remark = {
            cursor: "选择指针",
            direct: "结点连线",
            start: "入口结点",
            "end": "结束结点",
            "task": "任务结点",
            node: "自动结点",
            chat: "决策结点",
            state: "状态结点",
            plug: "附加插件",
            fork: "分支结点",
            "join": "联合结点",
            "complex mix": "复合结点",
            group: "组织划分框编辑开关"
        };
        var demo;
        $(document).ready(function () {
            demo = $.createGooFlow($("#demo"), property);
            demo.setNodeRemarks(remark);
            demo.onItemDel = function (id, type) {
                if (confirm("确定要删除该单元吗?")) {
                    this.blurItem();
                    return true;
                } else {
                    return false;
                }
            }
            demo.loadData(JSON.parse(jsondata));

            $("#1528855720244").css("background-color", "#5FB878");
            $("#1528855740178").css("background-color", "#5FB878");

        });
    }

});